package com.mercenary.wein.screenControl.ui.batch;

import com.mercenary.wein.screenControl.command.CommandTool;

import javax.swing.JDialog;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Greet extends JDialog {
    //Log log = LogFactory.getLog(ImportAddressBook.class);
    GroupCheckBoxPanel RequestJ1 = new GroupCheckBoxPanel();//面板1
    JPanel RequestJ2 = new JPanel();//面板2
    JCheckBox j1;
    static JFrame locationjf = new JFrame();

    public Greet() {
        super(locationjf, "打招呼");
        setBounds(200, 100, 700, 550);
        setLayout(new BorderLayout());
        setVisible(true);
        add(RequestJ1, BorderLayout.WEST);
        add(RequestJ2, BorderLayout.EAST);
        RequestJ1.setPreferredSize(new Dimension(180, 550));//设置大小
        RequestJ2.setLayout(new FlowLayout(FlowLayout.LEADING, 500, 10));
        RequestJ1.setBackground(Color.WHITE);
        RequestJ2.setPreferredSize(new Dimension(480, 550));
        RequestJ2.setBackground(Color.WHITE);
        //J2中的组件
        FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
        RequestJ2.setLayout(layout);
        JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp2 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp3 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp4 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp5 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        final ExeModeButtonGroup jp6 = new ExeModeButtonGroup(this);
        JPanel jp7 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        jp1.setPreferredSize(new Dimension(500, 30));//设置大小
        jp2.setPreferredSize(new Dimension(500, 30));//设置大小
        jp3.setPreferredSize(new Dimension(500, 30));//设置大小
        jp4.setPreferredSize(new Dimension(500, 20));//设置大小
        jp5.setPreferredSize(new Dimension(500, 150));//设置大小
        jp6.setPreferredSize(new Dimension(500, 170));//设置大小
        jp7.setPreferredSize(new Dimension(500, 40));//设置大小
        JLabel L1 = new JLabel("性别选择:");
        JLabel L2 = new JLabel("打招呼人数:");
        JLabel L3 = new JLabel("打招呼用语：（如果有多条，每个手机随机取一条）");
        JLabel L4 = new JLabel("~");
        JLabel L5 = new JLabel("秒");
        final JTextField num = new JTextField();
        num.setPreferredSize(new Dimension(35, 25));
        final JTextField start = new JTextField();
        start.setPreferredSize(new Dimension(35, 25));
        final JTextField end = new JTextField();
        end.setPreferredSize(new Dimension(35, 25));
        final JTextArea TextArea = new JTextArea(10, 40);
        TextArea.setTabSize(4);
        TextArea.setLineWrap(true);
        TextArea.setWrapStyleWord(true);
        final JCheckBox j1 = new JCheckBox("男");
        j1.setSelected(true);
        final JCheckBox j2 = new JCheckBox("女");
        ButtonGroup groups = new ButtonGroup();// 创建单选按钮组
        groups.add(j1);// 将radioButton1增加到单选按钮组中
        groups.add(j2);// 将radioButton2增加到单选按钮组中
        JCheckBox j3 = new JCheckBox("间隔");
        JRadioButton JRB1 = new JRadioButton("立即执行");
        JRadioButton JRB2 = new JRadioButton("定时执行");
        JRadioButton JRB3 = new JRadioButton("循环执行");
        ButtonGroup excutegroup = new ButtonGroup();// 创建单选按钮组
        excutegroup.add(JRB1);// 将radioButton1增加到单选按钮组中
        excutegroup.add(JRB2);// 将radioButton2增加到单选按钮组中
        excutegroup.add(JRB3);// 将radioButton2增加到单选按钮组中
        jp1.add(L1);
        jp1.add(j1);
        jp1.add(j2);
        jp2.add(L2);
        jp2.add(num);
        jp3.add(j3);
        jp3.add(start);
        jp3.add(L4);
        jp3.add(end);
        jp3.add(L5);
        jp4.add(L3);
        jp5.add(TextArea);

        JButton submit = new JButton("提交任务");
        jp7.add(submit);


        RequestJ2.add(jp1);
        RequestJ2.add(jp2);
        RequestJ2.add(jp3);
        RequestJ2.add(jp4);
        RequestJ2.add(jp5);
        RequestJ2.add(jp6);
        RequestJ2.add(jp7);

        submit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int gender = j1.isSelected()?0:1;
                int count = num.getText().matches("\\d+")?Integer.parseInt(num.getText()):1;
                CommandTool.sayHi(RequestJ1.getSelectedDevices(),count,gender,TextArea.getText(),jp6.getExeModeBean());
            }
        });
    }

    public static void main(String[] arge) {

    }


}
